package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PositionKeywords 位置关键词，用于搜索
type PositionKeywords struct {
	ID         string `json:"id"  gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	FloorID    string `json:"floor_id" gorm:"column:floor_id;type:int;size:64;comment:位置id;index:idx_keyword,priority:1"`
	PositionID string `json:"position_id" gorm:"column:position_id;type:int;size:64;comment:位置id"`
	Keyword    string `json:"keyword" gorm:"column:keyword;type:string;size:20;comment:关键词;index:idx_keywordpriority:2"`
}

// TableName 表名称
func (PositionKeywords) TableName() string {
	return "position_keywords"
}

// BeforeCreate 自增id
func (l *PositionKeywords) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PositionKeywords{})
}
